#!/usr/bin/env python3
#
# SVN Fakeupdate v1.0.0
# Copyright 2016 Florian Snow <florian@familysnow.net>
#
# This file is part of SVN Fakeupdate.
#
# SVN Fakeupdate is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

'''This module serves as the main executable and is not useful for importin.'''

import argparse
import os

import svnfu


def is_path_valid(parser, path):
    '''Check if a given path is valid.

    Return the full path name if the given path is valid.
    Raise a parser error if the given path is invalid or a file.
    '''
    if not os.path.exists(os.path.realpath(path)):
        parser.error("The path %s is not a valid path." % path)
    elif not os.path.isdir(os.path.realpath(path)):
        parser.error("%s is a file, not a path." %path)
    return os.path.realpath(path)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
      prog="Fake SVN Update",
      description=('Update all non-English transaltions '
        'for minor corrections in the English original.'),
      epilog=('This program is free software: you can redistribute it '
        'and/or modify it under the terms of the GNU General Public '
        'License as published by the Free Software Foundation, either '
        'version 3 of the License, or (at your option) any later version.'
        'This program is distributed in the hope that it will be useful, '
        'but WITHOUT ANY WARRANTY; without even the implied warranty of '
        'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the '
        'GNU General Public License for more details.'
        'You should have received a copy of the GNU General Public '
        'License along with this program.  If not, see '
        '<http://www.gnu.org/licenses/>.'))
    parser.add_argument(
      'path',
      help="the path of your SVN checkout directory",
      type=lambda path: is_path_valid(parser, path))
    args = parser.parse_args()
    fu = svnfu.SvnFu(args.path)
    fu.change_files()
